package co.yixiang.modules.quartz.task;

import co.yixiang.modules.shop.service.YxInvestOrderService;
import co.yixiang.modules.shop.websocket.MsgType;
import co.yixiang.modules.shop.websocket.SocketMsg;
import co.yixiang.modules.shop.websocket.WebSocketServer;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**认购信息推送机器人
 * @author frq
 * @date 2020-06-22
 */
@Slf4j
@Component
public class SubscripInformaPushTimer {
    @Autowired
    private YxInvestOrderService yxInvestOrderService;

    public void run(){
        //查询yx_invest_info_machine表随机数据进行推送
       List<Map<String,Object>> list=yxInvestOrderService.getMachine(1);
        for (Map<String,Object> map:list) {
            Map<String,Object> mapData=new LinkedHashMap<>();
            mapData.put("type", "investSuccess");
            mapData.put("msg", map.get("msg"));
            SocketMsg socketMsg = new SocketMsg(JSONObject.toJSONString(mapData), MsgType.INFO);
            try {
                WebSocketServer.sendInfo(socketMsg, null);
            } catch (IOException e) {
                log.error("推送失败：" +map.get("msg")+"====异常信息:"+e.getMessage());
            }
        }
    }

}
